package com.xiaoxin.codesandbox;

import cn.hutool.core.io.resource.ResourceUtil;
import com.xiaoxin.codesandbox.modle.ExecuteCodeRequest;
import com.xiaoxin.codesandbox.modle.ExecuteCodeResponse;
import org.springframework.stereotype.Component;

import java.nio.charset.StandardCharsets;
import java.util.Arrays;

/**
 * 实现代码沙箱接口
 */
@Component
public class JavaNativeCodeSandBoxImpl extends JavaCodeSandBoxTemplate {

    public static void main(String[] args) {
        ExecuteCodeRequest executeCodeRequest = new ExecuteCodeRequest();
        executeCodeRequest.setLanguage("java");
        executeCodeRequest.setCode(ResourceUtil.readStr("testCode/Main.java", StandardCharsets.UTF_8));
        executeCodeRequest.setInputList(Arrays.asList("1 2", " 3 4"));
        JavaNativeCodeSandBoxImpl codeSandBox = new JavaNativeCodeSandBoxImpl();
        ExecuteCodeResponse executeCodeResponse = codeSandBox.doExecute(executeCodeRequest);
        System.out.println(executeCodeResponse);
    }
}